
const inquirer = require('inquirer'); //命令行交互
const { exec } = require('child_process');
const { buildCheckbox } = require('../config.js');
const zip = require('../utils/zip.js');
module.exports = async () => {
      inquirer.prompt(buildCheckbox).then(result => { //inquirer 交互问答   
        const packages = result.Packages
        const project = result.project
        const mode = result.environment
        if(packages.length>0){
            packages.some(package => {
                console.warn(package,' building....');
                const exec = require('child_process').exec;
                let cmdStr = 'npm run build-'+ package  ;
                if(mode == 'test'){
                    cmdStr = `npm run build-${package}:${mode}`  ;
                }
                exec(cmdStr,{ 
                    maxBuffer: 200000*1024  /*stdout和stderr的最大长度*/
                  }, (err, stdout, stderr) => {
                    if (err){
                        console.log(err);
                        console.warn(package,' 编译命令执行失败');
                    } else {
                        console.log(stdout);
                        zip('./dist/',package,project,mode)
                        console.warn(package,' 编译命令执行成功');
                    }
                });
            })
         }
      })
 }

 